package com.lyf.design.practice.theory.behavior.strategy.nju.moviesale_20.v2;

/**
 * @author LYF
 * @date 2022/6/25
 */
public class SaleMovie {
    private Double price;
    private Integer point;
    private Discount discount;

    // 将策略注入
    public void setDiscount(Discount discount) {
        this.discount = discount;
    }

    // 用户也可直接通过传入--
    Double getLastPrice() throws Exception {//Double price,Integer point
        // 防止空指针，防御式编程---代码构造中的防御式和契约式编程
        if(discount==null)
            throw new Exception("No Set Strategy(com.lyf.design.practice.theory.behavior.strategy.nju.moviesale_20.v1.Discount)");
        // 考虑默认 降级策略
        return discount.getLastPrice(price);
    }

    Integer getLastPoint() throws Exception {
        if(discount==null)
            throw new Exception("No Set Strategy(com.lyf.design.practice.theory.behavior.strategy.nju.moviesale_20.v1.Discount)");
        // 对point处理
        return discount.getLastPoint(point);
    }

    // 用户通过构造器，将 price和point传入
    public SaleMovie(Double price, Integer point) {
        this.price = price;
        this.point = point;
    }
    // 用户通过setter注入
    public void setPrice(Double price) {
        this.price = price;
    }

    public void setPoints(Integer point) {
        this.point = point;
    }

}
